package com.foreveross.fetl.web.action.preprocess;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.foreveross.fetl.queue.AirChinaDomesticPreprocess;
import com.foreveross.fetl.queue.AirChinaInternationalPreprocess;
import com.foreveross.fetl.queue.AirChinaTaobaoPreprocess;
import com.foreveross.fetl.queue.AirLineCountProcess;
import com.foreveross.fetl.queue.AirSpreadPreprocess;
import com.foreveross.fetl.queue.CsairReportPreprocess;
import com.foreveross.fetl.queue.CsairTaobaoPreprocess;
import com.foreveross.fetl.queue.FlightOfficialAndChannelPulsStatistics;
import com.foreveross.fetl.queue.FlightOfficialAndChannelPulsTop5;
import com.foreveross.fetl.queue.FreightMonitorProcess;
import com.foreveross.fetl.queue.GenerateFlightInfo;
import com.foreveross.fetl.queue.HistoryDataPreprocess;
import com.foreveross.fetl.queue.HistoryDoubleDataPreprocess;
import com.foreveross.fetl.queue.LastestDataPreprocess;
import com.foreveross.fetl.queue.LastestDoubleDataPreprocess;
import com.foreveross.fetl.queue.LineDayPreprocess;
import com.foreveross.fetl.queue.MetadataCountPreprocess;
import com.foreveross.fetl.queue.MetadataDoublePreprocess;
import com.foreveross.fetl.queue.MetadataForAirsDoublePreprocess;
import com.foreveross.fetl.queue.MetadataForFtpPreprocess;
import com.foreveross.fetl.queue.PereMoreDataPreprocess;
import com.foreveross.fetl.queue.PriceRatioWarning;
import com.foreveross.fetl.util.DateUtils;
import com.opensymphony.xwork2.ActionSupport;

@Controller("manualPreProcessAction")
@Scope("prototype")
public class ManualPreProcessAction extends ActionSupport {
	private static final long serialVersionUID = -7942653801482842953L;

	@Inject private FreightMonitorProcess freightMonitorProcess;

	@Inject private PriceRatioWarning priceRatioWarning;
	
	@Inject private LastestDoubleDataPreprocess lastestDoubleDataPreprocess;
	
	@Inject private FlightOfficialAndChannelPulsTop5 flightOfficialAndChannelPulsTop5;
	
	@Inject private FlightOfficialAndChannelPulsStatistics flightOfficialAndChannelPulsStatistics;
	
	@Inject private LastestDataPreprocess lastestDataPreprocess;
	
	@Inject private HistoryDataPreprocess historyDataPreprocess;
	
	@Inject private GenerateFlightInfo generateFlightInfo;
	
	@Inject private HistoryDoubleDataPreprocess historyDoubleDataPreprocess;
	
	@Inject private CsairReportPreprocess csairReportPreprocess;
	
	@Inject private AirSpreadPreprocess airSpreadPreprocess;
	
	@Inject private AirChinaDomesticPreprocess airChinaDomesticPreprocess;
	
	@Inject private AirChinaInternationalPreprocess airChinaInternationalPreprocess;
	
	@Inject private CsairTaobaoPreprocess csairTaobaoPreprocess;
	
	@Inject private AirChinaTaobaoPreprocess airChinaTaobaoPreprocess;
	
	@Inject private MetadataForFtpPreprocess metadataForFtpPreprocess;
	
	@Inject private LineDayPreprocess lineDayPreprocess;
	
	@Inject private PereMoreDataPreprocess pereMoreDataPreprocess;
	
	@Inject private MetadataDoublePreprocess metadataDoublePreprocess;
	
	
	@Inject private MetadataForAirsDoublePreprocess metadataForAirsDoublePreprocess;
	
	@Inject private MetadataCountPreprocess metadataCountPreprocess;
	
	@Inject private AirLineCountProcess airLineCountProcess;
	
	private String suc;

	public String process() throws Exception {
		HttpServletRequest req = ServletActionContext.getRequest();
		String method = req.getParameter("method");
		String start = req.getParameter("start");
		String time = req.getParameter("time");
		if (time != null && !"".equals(time)) {
			List<String> timeList = Arrays.asList(time.split(";"));
			String timeStart = start + timeList.get(0);
			Date timeForStart = DateUtils.parse(timeStart, "yyyyMMddHH");
			if ("top5".equals(method)) {
				flightOfficialAndChannelPulsTop5.rollBackNumber();
				flightOfficialAndChannelPulsTop5.processOfficalChannelPlus(timeForStart);
			} else if ("plus".equalsIgnoreCase(method)) {
				flightOfficialAndChannelPulsStatistics.execute();
			} else {
				if ("lastDouble".equalsIgnoreCase(method)) {
					lastestDoubleDataPreprocess.manualExecute(start, time);
				} else if ("last".equalsIgnoreCase(method)) {
					lastestDataPreprocess.manualExecute(start, time);
				} else if ("history".equalsIgnoreCase(method)) {
					historyDataPreprocess.manualExecute(start, time);
				} else if ("historyDouble".equalsIgnoreCase(method)) {
					historyDoubleDataPreprocess.manualExecute(start, time);
				} else if ("generate".equalsIgnoreCase(method)) {
					generateFlightInfo.manualExecute(start, time);
				} else

				if ("monitor".equalsIgnoreCase(method)) {
					freightMonitorProcess.manualTypeExecute(start, time);
				} else if ("cabin".equalsIgnoreCase(method)) {
					freightMonitorProcess.manualCabinExecute(start, time);
				} else if ("ratio".equalsIgnoreCase(method)) {
					priceRatioWarning.manualRatioExecute(start, time);
				} else if ("auction".equalsIgnoreCase(method)) {
					priceRatioWarning.manualAuctionExecute(start, time);
				} else

				if ("csairReport".equalsIgnoreCase(method)) {
					csairReportPreprocess.manualExecute(start, time);
				} else if ("csairDomestic".equalsIgnoreCase(method)) {
					csairReportPreprocess.manualDomesticExecute(start, time);
				} else if ("airSpread".equalsIgnoreCase(method)) {
					airSpreadPreprocess.manualExecute(start, time);
				} else if ("airChinaDomestic".equalsIgnoreCase(method)) {
					airChinaDomesticPreprocess.manualExecute(start, time);
				} else if ("airChinaInternational".equalsIgnoreCase(method)) {
					airChinaInternationalPreprocess.manualExecute(start, time);
				} else if ("csairTaobao".equalsIgnoreCase(method)) {
					csairTaobaoPreprocess.manualExecute(start, time);
				} else if ("airChinaTaobao".equalsIgnoreCase(method)) {
					airChinaTaobaoPreprocess.manualExecute(start, time);
				} else if ("metadata".equalsIgnoreCase(method)) {
					metadataForFtpPreprocess.manualExecute(start, time);
				} else if ("metadataAll".equalsIgnoreCase(method)) {
					metadataForFtpPreprocess.manualExecute(start);
				} else if ("lineDay".equalsIgnoreCase(method)) {
					lineDayPreprocess.manualExecute(start, time);
				} else if ("pereMoreData".equalsIgnoreCase(method)) {
					pereMoreDataPreprocess.execute();
				}else if ("metadataDouble".equalsIgnoreCase(method)) {
					metadataDoublePreprocess.manualExecute(start, time);
				} else if ("metadataAllDouble".equalsIgnoreCase(method)) {
					metadataDoublePreprocess.manualExecute(start);
				}else if ("metadataForAirs".equalsIgnoreCase(method)) {
					 metadataForAirsDoublePreprocess.manualExecute(start, time);
				}else if("airLineCount".equalsIgnoreCase(method)){
					airLineCountProcess.manualExecute(start);
				}
				
			}

		}
		suc = "true";
		return "JSON";
	}

	public String list() {
		return "METHOD";
	}
	
	public String hangxinList(){
		return "METHOD";
	}
	
	public String hangxinProcess(){
		HttpServletRequest req = ServletActionContext.getRequest();
		String channel = req.getParameter("channel");
		String start = req.getParameter("start");
		String end = req.getParameter("end");
		String type =req.getParameter("type");
		if("ftp".equalsIgnoreCase(type)){
			metadataForAirsDoublePreprocess.hangxinExcute(start, end, channel);	
		}else if("count".equalsIgnoreCase(type)){
			Date startTime = DateUtils.parse(start, "yyyyMMddHH");
			Date endTime = DateUtils.parse(end, "yyyyMMddHH");
			metadataCountPreprocess.countforExcel(startTime, endTime);
			//metadataCountPreprocess.countforExcel();
		}

		suc = "true";
		return "JSON";
	}

	public String getSuc() {
		return suc;
	}

	public void setSuc(String suc) {
		this.suc = suc;
	}
}
